package bishi.alibaba;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2020/11/25 09:52
 */
public class _45 {
    public static void main(String[] args) {
        System.out.println(solution(8, new int[]{3, 2, 1, 5, 3, 4, 9, 5}));
    }
    public static int solution(int n, int[] nums) {
        if (n < 1) {
            return 0;
        }
        int[][] daan = new int[100001][1];
        int i = 0;
        int maxIndex = 0;
        while (i < n) {
            daan[nums[i]][0]++;
            maxIndex = Math.max(maxIndex,nums[i]);
            i++;
        }
        i = 0;
        int max = 0;
        while (i <= maxIndex) {
            max = Math.max(max, daan[i][0] + (i > 0 ? daan[i - 1][0] : 0) + (i < n - 1 ? daan[i + 1][0] : 0));
            i++;
        }
        return max;
    }
}
